package com.yanqu.road.server.cmd.activity.businessreunion;

import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.BusinessReunionProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.activity.businessreunion.BusinessReunionMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2022/4/19 11:25
 */
@Cmd(code = GameProtocol.S_CROSS_RECALL_BIND, desc = "召回绑定")
public class CrossRecallBindCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        BusinessReunionProto.WriteRecallCodeCrossReqMsg reqMsg = BusinessReunionProto.WriteRecallCodeCrossReqMsg.parseFrom(packet.getBytes());
        BusinessReunionProto.WriteRecallCodeReqCrossMsg reqCrossMsg = reqMsg.getReqCrossMsg();
        int ret = BusinessReunionMgr.recallBind(reqCrossMsg.getReqBindUserId(), reqMsg.getOriUserId(), PlayerBasePb.parseBaseUserInfo(reqCrossMsg.getRecallUserInfo()), reqCrossMsg.getRecallCode());
        BusinessReunionProto.WriteRecallCodeRespCrossMsg.Builder respCrossMsg = BusinessReunionProto.WriteRecallCodeRespCrossMsg.newBuilder();
        respCrossMsg.setRecallCode(reqCrossMsg.getRecallCode());
        respCrossMsg.setRespServerId(reqMsg.getOriServerId());
        respCrossMsg.setRespUserId(reqMsg.getOriUserId());
        respCrossMsg.setRet(ret);
        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_CROSS_RECALL_BIND_RESP, respCrossMsg);
        GamePlayerMgr.sendPacket(0, message);
    }
}
